package TestPackage;

import static org.junit.Assert.*;

import java.sql.Connection;
import java.util.ArrayList;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import DBLayer.*;
import ModelLayer.*;

public class DBProductTest {

	private DBProduct dbProduct;

	@Before
	public void setUp() throws Exception {
		dbProduct = new DBProduct();

	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testDeleteProduct() {

		dbProduct.deleteProduct(1);

	}

	@Test
	public void testFindProduct() {

		Product pro = dbProduct.findProduct(2, false);
		if (pro != null) {
			System.out.println(pro.getCarModel());
		} else
			System.out.println("fail");

	}

	@Test
	public void testListAllProducts() {
		ArrayList<Product> pro = dbProduct.listAllProducts(false);

		System.out.println(pro.size());

	}

	@Test
	public void testListAllProductsFromSupplier() {
		fail("Not yet implemented");
	}

	@Test
	public void testUpdateProduct() {
		Gearbox gear = new Gearbox();
		Supplier sup = new Supplier(123456789, "Auto reservedele", "DK",
				1245458, "la@ja.com");

		gear.setProductNumber(1);
		gear.setSerialNumber(123456);
		gear.setSupplier(sup);
		gear.setProductName("earbox");
		gear.setPurchasePrice(1000.00);
		gear.setSalesPrice(2000.00);
		gear.setRentPrice(100.00);
		gear.setCountryOfOrigin("Polen");
		gear.setFabricant("lala");
		gear.setDescription("lalagear");
		gear.setCarModel("Lada");
		gear.setModelYear(1985);
		gear.setMinStock(10);
		gear.setMaxStock(20);
		gear.setGearboxType("go");
		gear.setGearAmount(3);
		gear.setProductType("gearbox");

		try {
			dbProduct.updateProduct(gear);
		} catch (Exception e) {
			System.out.println("Product ikke opdateret");
		}
	}

	@Test
	public void testInsertGearProduct() {

		Gearbox gear = new Gearbox();
		Supplier sup = new Supplier(123456789, "Auto reservedele", "DK",
				1245458, "la@ja.com");

		//gear.setProductNumber(2);
		gear.setSerialNumber(123999);
		gear.setSupplier(sup);
		gear.setProductName("lala123");
		gear.setPurchasePrice(100.00);
		gear.setSalesPrice(20.00);
		gear.setRentPrice(0.0);
		gear.setCountryOfOrigin("China");
		gear.setFabricant("blubla");
		gear.setDescription("lalagear");
		gear.setCarModel("lada");
		gear.setModelYear(1963);
		gear.setMinStock(10);
		gear.setMaxStock(20);
		gear.setGearboxType("go");
		gear.setGearAmount(3);
		gear.setProductType("gearbox");

		try {
			dbProduct.insertProduct(gear);
			System.out.println("Product inserted");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	public void testInsertTireProduct() {

		Tire tire = new Tire();
		Supplier sup = new Supplier(123456789, "Auto reservedele", "DK",
				1245458, "la@ja.com");

		//gear.setProductNumber(2);
		tire.setSerialNumber(123999);
		tire.setSupplier(sup);
		tire.setProductName("lala123");
		tire.setPurchasePrice(100.00);
		tire.setSalesPrice(20.00);
		tire.setRentPrice(0.0);
		tire.setCountryOfOrigin("China");
		tire.setFabricant("Michelin road");
		tire.setDescription("blablabla");
		tire.setCarModel("lada");
		tire.setModelYear(1963);
		tire.setMinStock(10);
		tire.setMaxStock(20);
		tire.setTireType("summer");
		tire.setTireSize("205/45/17");
		tire.setProductType("Tire");

		try {
			dbProduct.insertProduct(tire);
			System.out.println("Product inserted");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
